package ar.com.vates.ejercicio06;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Metodos {

	public static String leer() {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		try {
			String leido=br.readLine();
			return leido;
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
	}

	public static String mayusculas(String cadena) {
		if(cadena!=null) {
			String aux=cadena.toUpperCase();
			return aux;
		}
		return null;
		
	}

	public static String minusculas(String cadena) {
		if(cadena!=null) {
			String aux=cadena.toLowerCase();
			return aux;
		}
		return null;
		
	}

	public static String dosPrimeros(String cadena) {
		if(cadena!=null&&cadena.length()>=2) {
			String aux=cadena.substring(0, 2);
			return aux;
		}
		return null;
		
	}

	public static String dosUltimos(String cadena) {
		if(cadena!=null&&cadena.length()>=2) {
			String aux=cadena.substring(cadena.length()-2, cadena.length());
			return aux;
		}
		return null;
	}

	public static int ocurrenciasUltimoCaracter(String cadena) {
		if(cadena!=null) {
			char caracter=cadena.charAt(cadena.length()-1);
			int ocurrencias=0;
			for(int i=0;i<cadena.length();i++) {
				if(cadena.charAt(i)==caracter) ocurrencias++;
			}
			return ocurrencias;
		}
		return -1;
	}

	public static String ocurrenciasPrimerCaracter(String cadena) {
		if(cadena!=null) {
			char caracter=cadena.charAt(0);
			String aux= new String(cadena);
			aux=aux.replaceAll(Character.toString(caracter).toLowerCase(), Character.toString(Character.toUpperCase(caracter)));
			return aux;
		}
		return null;
		
	}

	public static String tresAsteriscos(String cadena) {
		if(cadena!=null) {
			return new String("***"+cadena+"***");
		}
		return null;
	}

	public static String cadenaInvertida(String cadena) {
		if(cadena!=null) {
			char[]charCadena=cadena.toCharArray();
			char[]charAux=cadena.toCharArray();
			int j=cadena.length()-1;
			for(int i=0;i<cadena.length();i++) {
				charAux[i]=charCadena[j];
				j--;
			}
			return new String(charAux);
		}
		return null;
	}

}
